package symbolTable;

import java.util.LinkedHashMap;
import java.util.Map;

public class FunctionSymbol extends Symbol implements  Scope{
    public Map<String, Symbol> arguments = new LinkedHashMap<>();
    public Scope enclosingScope;

    public Map<String, Symbol> results = new LinkedHashMap<String, Symbol>();

    public FunctionSymbol(String name, Scope enclosingScope) {
        super(name);
        this.enclosingScope = enclosingScope;
    }

    @Override
    public String getScopeName() {
        return name;
    }

    @Override
    public Scope getEnclosingScope() {
        return this.enclosingScope;
    }

    @Override
    public void define(Symbol symbol) {
        arguments.put(symbol.name, symbol);
        symbol.scope = this;
    }

    @Override
    public Symbol search(String name) {
        if (this.arguments.get(name) != null) {
            return this.arguments.get(name);

        }
        return this.results.get(name);
    }

    @Override
    public String toString() {
        return "FunctionSymbol{" +
                "arguments=" + arguments +
                ", enclosingScope=" + enclosingScope +
                ", results=" + results +
                ", name='" + name + '\'' +
                ", type=" + type +
                ", scope=" + scope +
                '}';
    }
}
